%{
// Simple Logo - Analisador Léxico

#include <stdio.h>
#include "simplelogo-sintatico.tab.h"

// Conta o número de linhas
int nl = 1;

%}

linebreak       [\n]
blankspace      [ \t]+
intnum          [0-9]+
variable        $[A-Za-z][A-Za-z0-9]*
comment         "#"[^\n]*"\n"
turnleft        turnleft
turnright       turnright
go              go
gox	        		gox
goy	        		goy
pencolor        pencolor
penwidth        penwidth
canvascolor     canvascolor
canvassize      canvassize
if_             "if"
for_            "for"
wait_	        	"wait"
reset_          "reset"
direction       "direction"
repeat_         "repeat"
while_          "while"
penup           "penup"
pendown         "pendown"
to              "to"
openbracket     "{"
closebracket     "}"
openpar          "("
closepar         ")"
commas           ","
true_	         	 "true"
false_           "false"
greater          ">"
less             "<"
equal            "="
more             "+"
minus_            "-"
mult             "*"
division         "/"
and_             "and"
or_              "or"
forward          "forward"
backward         "backward"
write_           "write"
text_            \"[^\n]*\"
%%
{write_}             {return write_;}
{text_}	     	       {strcpy(yylval.id, yytext); return text_;}
{backward}           {return backward;}
{linebreak}          {nl++;}
{forward}            {return forward;}
{greater}	           {return greater;}    
{less}    	         {return less;}
{equal}    	         {return equal;}
{more}     	         {return more;}
{minus_}    	         {return minus_;}
{mult}    	         {return mult;}
{division}     	     {return division;}
{and_}      	       {return and_;}
{or_}       	       {return or_;}
{true_}	     	       {strcpy(yylval.id, "true") ; return true_;}
{false_}	           {strcpy(yylval.id,"false"); return false_;}
{blankspace}         {}
{commas}	           {return commas;}
{to}		             {return to_;}
{openbracket}	       {return openbracket;}
{closebracket}	     {return closebracket;}
{openpar}	           {return openpar;}
{closepar}	         {return closepar;}
{variable}	         {strcpy(yylval.id, yytext);return variable;}
{intnum}             {strcpy(yylval.id,yytext);return intnum;}
{comment} 	         {}
{if_}                {return if_;}
{repeat_}      	     {return repeat_;}
{for_}	             {return for_;}
{wait_}              {return wait_;}
{while_}	           {return while_;}
{turnleft}           {return turnleft;}
{turnright}   	     {return turnright;}
{direction}    	     {return direction;}
{go}         	       {return go;}
{gox}        	       {return gox;}
{goy}        	       {return goy;}
{reset_}	           {return reset;}
{penup}        	     {return penup;}
{pendown}      	     {return pendown;}
{pencolor}  	       {return pencolor;}
{penwidth}   	       {return penwidth;}
{canvassize} 	       {return canvassize;}
{canvascolor} 	     {return canvascolor;}
.	     	             {printf("Erro na análise léxica linha %d: token que começa com letra '%s' é desconhecido\n", nl, yytext); exit(0);}
%%
